/*
 * @Description: 
 * @Version: 
 * @Author: BaiYiZhuo
 * @Date: 2022-01-29 18:37:16
 * @LastEditTime: 2022-01-29 20:34:45
 */
#include <Arduino.h>
/*
 * @Description: 
 * @Version: 
 * @Author: BaiYiZhuo
 * @Date: 2022-01-28 12:09:44
 * @LastEditTime: 2022-01-29 18:27:10
 */
#include <Arduino.h>
#include <esp_task_wdt.h>
#include <Bounce2.h>
#define BUTTON 22
#define LEDPIN 23
#define WDT_TIMEOUT 3 // WDT Timeout in seconds
volatile u_int chooseState = 0;
u_int count = 0;
void changeStateInterrupt();
void setup()
{
    pinMode(BUTTON, INPUT_PULLUP);
    pinMode(LED_BUILTIN, OUTPUT);
    digitalWrite(LED_BUILTIN, HIGH);

    pinMode(LEDPIN, OUTPUT);
    digitalWrite(LEDPIN, HIGH);

    Serial.begin(115200);
    Serial.print("初始化.....");

    esp_task_wdt_init(WDT_TIMEOUT, true); // Initialize ESP32 Task WDT
    esp_task_wdt_add(NULL);               // Subscribe to the Task WDT
    attachInterrupt(digitalPinToInterrupt(BUTTON), changeStateInterrupt, RISING);
}
void loop()
{
    switch (chooseState)
    {
        //     // case 0:
        //     //     Serial.println("没有中断处理情况：");
        //     //     break;

    case 1:
    {
        Serial.print("出现中断情况！处理中断->>>");
        Serial.print("  中断处理次数为：");
        Serial.println(count);
        chooseState = 0;
        break;
    }
    }
    esp_task_wdt_reset();
}
void changeStateInterrupt()

{
    count++;
    chooseState = 1;
    while (!digitalRead(BUTTON))
    {
    }
    delay(200);

    // chooseState = 1;
    // count++;
}